package com.coinworld.producer;

import com.google.gson.Gson;
import com.coinworld.entity.User;
import com.coinworld.entity.vo.RabbitmqVo;
import com.coinworld.log.MqSendLog;
import com.coinworld.utils.ShareCodeUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * Created by ZhangRuiFeng on 2019/5/15.
 */

@Service
public class SendService {

    @Autowired
    private RabbitTemplate template;
    @Resource
    private Gson gson;


    public void setDiligenceUpdate(User user){
        if(null != user.getId()){
            template.convertAndSend("diligenceUpdate",user.getId());
        }
        if (null != user.getParentFirst()){
            template.convertAndSend("diligenceUpdate",user.getParentFirst());
        }
        if (null != user.getParentSecond()){
            template.convertAndSend("diligenceUpdate",user.getParentSecond());
        }
    }

    public void setRabbitMqVo(String mobile, Integer type, String orderNo, BigDecimal money, String payType){
        RabbitmqVo rabbitmqVo=new RabbitmqVo();
        rabbitmqVo.setType(type);
        rabbitmqVo.setMobile(mobile);
        rabbitmqVo.setMoney(money);
        rabbitmqVo.setOrderNo(orderNo);
        rabbitmqVo.setPayType(payType);
        rabbitmqVo.setTrxId(ShareCodeUtil.generateShortUuid());
        MqSendLog.logData(gson.toJson(rabbitmqVo));
        template.convertAndSend("rewardQueue",rabbitmqVo);
    }

    /**
     * 发送发旅游卡
     * @param orderSn
     */
    public void sendTripCard(String orderSn){
        MqSendLog.logData(gson.toJson(orderSn));
        template.convertAndSend("sendTripCard",orderSn);
    }

}
